using System;
using System.Collections.Generic;
using System.Text;

using System.Xml.Serialization;

using AI.AStar;
using System.Diagnostics;

namespace GameMap
{
    public class Station : IAStarNode
    {
        private int m_StationID;

        private List<int> m_TaxiConnections;
        private List<int> m_BusConnections;
        private List<int> m_UndergroundConnections;
        private List<int> m_BoatConnections;

        #region Constructors

        // parameterless constructor for xml serialization
        public Station()
        {
            m_StationID = -1; // uninitialized station

            m_TaxiConnections = new List<int>();
            m_BusConnections = new List<int>();
            m_UndergroundConnections = new List<int>();
            m_BoatConnections = new List<int>();
        }

        public Station(int station_id)
        {
            m_StationID = station_id;

            m_TaxiConnections = new List<int>();
            m_BusConnections = new List<int>();
            m_UndergroundConnections = new List<int>();
            m_BoatConnections = new List<int>();
        }

        #endregion

        #region Methods
        
        public void AddTaxiConnection(int taxi_connection)
        {
            m_TaxiConnections.Add(taxi_connection);
        }

        public void AddBusConnection(int bus_connection)
        {
            m_BusConnections.Add(bus_connection);
        }

        public void AddUndergroundConnection(int undergournd_connection)
        {
            m_UndergroundConnections.Add(undergournd_connection);
        }

        public void AddBoatConnection(int boat_connection)
        {
            m_BoatConnections.Add(boat_connection);
        }

        #endregion

        #region Properties 

        public int StationID
        {
            set { m_StationID = value; }
            get { return m_StationID; }
        }

        public List<int> TaxiConnections
        {
            get { return m_TaxiConnections; }
        }

        public List<int> BusConnections
        {
            get { return m_BusConnections; }
        }

        public List<int> UndergroundConnections
        {
            get { return m_UndergroundConnections; }
        }

        public List<int> BoatConnections
        {
            get { return m_BoatConnections; }
        }

        #endregion
        
        #region IAStarNode Members

        public List<IAStarNode> Successors(IAStarSearchSpace search_space)
        {
            StationsNetwork stationsNetwork = search_space as StationsNetwork;
            List<IAStarNode> successors = new List<IAStarNode>();
            foreach (int station_id in m_TaxiConnections)
            {
                successors.Add((IAStarNode)stationsNetwork.GetStation(station_id));
            }

            return successors;
        }

        public int CalculateHCostTo(IAStarNode targetNode)
        {
            return 0; // no heuristic for now
        }

        public int CalculateGCostTo(IAStarNode targetNode)
        {
            return 1;
        }

        bool IAStarNode.Equals(object obj)
        {
            Station stationToTest = ((IAStarNode)obj) as Station;
            return this.StationID == stationToTest.StationID;
        }
        
        #endregion

        #region Overrides
        public override string ToString()
        {
            return m_StationID.ToString();
        }
        #endregion

    }
}
